package com.hyl.ssm.javaconfig;

import org.apache.commons.dbcp2.BasicDataSource;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.*;

/**
 * com.hyl.ssm.javaconfig.SpringConfigration
 *
 * @author hyl
 * @date 2024-12-18
 */
@Configuration
@PropertySource(value = "classpath:database.properties",encoding = "utf-8")
@ComponentScan("com.hyl.ssm")
public class SpringConfigration {

    @Value("${jdbc.driver}")
    private String driver;
    @Value("${jdbc.url}")
    private String url;
    @Value("${jdbc.username}")
    private String username;
    @Value("${jdbc.password}")
    private String password;


    public BasicDataSource dataSource(){
        BasicDataSource dataSource = new BasicDataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

    @Bean
    public SysUser getSysUser(SysRole role) {
        SysUser sysUser = new SysUser();
        sysUser.setPassword("123456");
        sysUser.setUsername("aa");
        sysUser.setRole(role);
        return sysUser;
    }

    @Bean
    @Primary  //主要的，默认的
    public SysRole adminRole(){
        SysRole sysRole = new SysRole();
        sysRole.setRoleName("admin");
        return sysRole;
    }

    @Bean
    public SysRole empRole(){
        SysRole sysRole = new SysRole();
        sysRole.setRoleName("employee");
        return sysRole;
    }
}
